package org.alis.smallcc.alis.tools.lock.distributed;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;

import org.alis.smallcc.alis.tools.lock.LockManager;
/**
 * 抽象方法锁
 * 
 * @author: luochuan     
 * @date: 2020年10月29日 下午6:48:07
 */
public abstract class AbstrackLockManager implements LockManager{

    private final Map<String, Lock> lockStore = new ConcurrentHashMap<>(128);
    private final Map<String, ReadWriteLock> readWriteLockStore = new ConcurrentHashMap<>(128);

    @Override
    public Lock getLock(String lockName) {
        return lockStore.computeIfAbsent(lockName, this::createLock);
    }

    @Override
    public ReadWriteLock getReadWriteLock(String lockName) {
        return readWriteLockStore.computeIfAbsent(lockName, this::createReadWriteLock);
    }

    protected abstract Lock createLock(String lockName);

    protected abstract ReadWriteLock createReadWriteLock(String lockName);

}
